/**
 * 面试题10-1：求斐波那契数列的第n项
 */
public class Offer_10_I {
    /**
     * 方法二：迭代
     */
    public int fib(int n) {
        int a = 0, b = 1, sum = 0;
        for (int i = 0; i < n; i++) {
            sum = (a + b) % 1000000007;
            a = b;
            b = sum;
        }
        return a;
    }

    /**
     * 方法一：递归（效率很低）
     */
    public int fib1(int n) {
        if (n == 0) {
            return 0;
        }
        if (n == 1) {
            return 1;
        }
        return fib(n - 1) + fib(n - 2);
    }

    public static void main(String[] args) {
        Offer_10_I solution = new Offer_10_I();
        int ans = solution.fib(50);
        System.out.println(ans);
    }
}
